﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommonLibrary.DataModel.Basic;
using System.Data.SqlClient;
using CommonLibrary.DB;
using System.Data;

namespace ServiceApplication.Dao.Basic
{
    public class GzzdDao
    {
        /// <summary>
        /// 增加一条新的修改
        /// </summary>
        /// <param name="gzzdEntity"></param>
        /// <returns></returns>
        public int AddEntity(GzzdEntity gzzdEntity)
        {
            List<SqlParameter> parameterList = new List<SqlParameter>();
            parameterList.Add(new SqlParameter("@gzzd_detail", gzzdEntity.gzzd_detail));
            parameterList.Add(new SqlParameter("@gzzd_detail2", gzzdEntity.gzzd_detail2));
            parameterList.Add(new SqlParameter("@gzzd_xgsj", gzzdEntity.gzzd_xgsj));

            string sql = "insert into jc_gzzd (gzzd_detail,gzzd_detail2,gzzd_xgsj) values (@gzzd_detail,@gzzd_detail2,@gzzd_xgsj);" +
                " select @@identity";

            string id = DBExecuteUtil.getUniqueResult(sql, parameterList.ToArray());

            return int.Parse(id);
        }

        /// <summary>
        /// 返回规则制定最新的查询结果
        /// </summary>
        /// <returns></returns>
        public GzzdEntity QueryEntity()
        {
            GzzdEntity gzzdEntity = null;

            string sql = "select gzzd_id,gzzd_detail,gzzd_detail2,gzzd_xgsj from jc_gzzd where gzzd_id=(select max(gzzd_id) from jc_gzzd)";

            var result = DBExecuteUtil.querySqlArray(sql);

            if (null == result)
            {
                return null;
            }

            gzzdEntity = new GzzdEntity();
            gzzdEntity.gzzd_id = int.Parse(result[0][0]);
            gzzdEntity.gzzd_detail = result[0][1];
            gzzdEntity.gzzd_detail2 = result[0][2];
            gzzdEntity.gzzd_xgsj = result[0][3];

            return gzzdEntity;
        }

    }
}
